package learn.advance.iterator1;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

class Demo01Iterator{
    public static void Test(){
        Collection<String> coll=new ArrayList<>(11);
        coll.add("姚明");
        coll.add("科比");
        coll.add("麦迪");

        Iterator<String> it=coll.iterator();

        while(it.hasNext()){
            String e=it.next();
            System.out.println(e);
        }

        System.out.println("=========================");
        for (Iterator<String> it2=coll.iterator();it2.hasNext();){
            String e=it2.next();
            System.out.println(e);
        }
    }
}
class Demo02Foreach{
    public static void Test(){

        Demo1();
        Demo2();
    }

    private static void Demo2(){
        ArrayList<String> list =new ArrayList<>();
        list.add("aaa");
        list.add("bbb");
        list.add("ccc");
        for(String s:list){
            System.out.println(s);
        }

        System.out.println("================");
    }

    private static void Demo1(){
        int [] arr={1,2,3,4};
        for(int i:arr){
            System.out.println(i);
        }
    }

}


public class TestIterator {
    public static void main(String[] args) {
        //Demo01Iterator.Test();
        Demo02Foreach.Test();
    }
}
